package com.est.dase.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.est.dase.R;
/**
*
* @author Fernando Geraldes, Jaime Santos, Jorge Silva
*
*/
public class ListAdapterSettings extends BaseAdapter {

	private Activity activity;
	private String[] data;
	private static LayoutInflater inflater=null;
	int[] images;
	/**
	 * Constructor
	 */
	public ListAdapterSettings(Activity a, String[] d, int[] i) {
		activity = a;
		data=d;
		images = i;
		inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		//ImageView img = (ImageView) findViewById(R.id.profile_pic);
	}

	/**
	 * getCount
	 * @return int data length
	 */
	public int getCount() {
		return data.length;
	}

	/**
	 * getItem
	 * @return int position
	 */
	public Object getItem(int position) {
		return position;
	}

	/**
	 * getItemId
	 * @return long position
	 */
	public long getItemId(int position) {
		return position;
	}

	/**
	 * ViewHolder class
	 * @author Tim w.e Lab
	 *
	 */
	public static class ViewHolder{
		public TextView text;
		public ImageView image;

	}

	/**
	 * getView
	 * @param position int
	 * @param convertView View
	 * @param parent ViewGroup
	 * @return View
	 */
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi=convertView;
		ViewHolder holder;
		//check convertView
		if(convertView==null){
			//create View vi
			vi = inflater.inflate(R.layout.list_settings, null);
			//create ViewHolder holder
			holder=new ViewHolder();
			/*
			 * create views in holder components
			 */
			holder.text=(TextView)vi.findViewById(R.id.textListSettings);
			holder.image=(ImageView)vi.findViewById(R.id.imageListSettings);
			
			//put holder in tag vi
			vi.setTag(holder);
		}
		else{
			//create ViewHolder with vi tag
			holder=(ViewHolder)vi.getTag();
		}

		/*
		 * construct holder components 
		 */

		holder.text.setText(data[position]);
		holder.image.setImageResource(images[position]);

		return vi;

	}

}

